<?php
require_once("Mail.php");
/************************************
 External Libraris
*************************************/	
if (strstr(strtolower($_SERVER['SystemRoot']), "windows")) {
    ini_set("include_path", ini_get("include_path").'.;./libs/');   
} else {
    // Assume Unix environment
    ini_set("include_path", ini_get("include_path").'.:./libs/'); 
}

/************************************
 Misc
*************************************/

ini_set("default_charset", "UTF-8");
setlocale(LC_ALL, array('no_NO.UTF-8', 'norwegian'));
header("Content-type: text/html; charset=UTF-8");
ini_set("allow_url_fopen", "On");
set_time_limit(500);

/************************************
 Database
*************************************/

if (strstr($_SERVER['SystemRoot'], "WINDOWS")) {
    // Assume LOCAL server 
    $CONFIG['environment'] = "localConfig";
} else {
    // Assume REMOTE server
    $CONFIG['environment'] = "remoteConfig";
}

/************************************
 Error Handling
*************************************/

set_error_handler("Lastfm_error_handler");
function Lastfm_error_handler($errtype, $errstr, $errfile, $errline ) {
    
    switch ($errtype)
    {
        case E_USER_ERROR:
            echo '<font color="red">'.$errstr."</font> in <strong>".$errfile."</strong> 
                  on line <strong>".$errline."</strong><br />";
            Mail::sendNotification("an error has occured","\"".$errstr."\"\n\nFile: ".$errfile." on line ".$errline);
            break;
        case E_USER_WARNING:
            echo '&nbsp;WARNING: <font color="red">'.$errstr."</font><br />";
            break;
        case E_USER_NOTICE:
            echo '&nbsp;NOTICE: <em>'.$errstr."</em>><br />";
            break;
        default: 
            break;
    }
    
    return true;
}

function resultSort($a, $b) {
    if ($a->artist->weight == $b->artist->weight) {
        return 0;
    }
    return ($a->artist->weight > $b->artist->weight) ? -1 : 1;
}
?>